/**
 * 
 */
package com.base.myproject.client.busi;

import java.util.Date;

import com.base.myproject.client.busi.b2c.MainPage;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.system.Login;
import com.base.myproject.client.tools.DateUtil;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * 
 * @author zgw
 *2009-8-3 下午04:56:41
 * javazgw@gmail.com
 */
public class URLFactory {
	
	private URLFactory()
	{
		
	}
	public static void Factory()
	{
		String PMServer;
		PMServer = 
			"http://"+com.google.gwt.user.client.Window.Location.getHost()+ "/"; 
		String path = com.google.gwt.user.client.Window.Location.getPath();
		
		if(path.indexOf("manager")>0 || path.indexOf("oa")>0)
		{
			GWT.runAsync(new RunAsyncCallback(){
		         public void onFailure(Throwable err){
		            Window.alert("代码下载错误，错误可能源自网络链接已经断了。");
		         }
		 
		         public void onSuccess(){
		        	/*验证代码开始=======================*/
		        	 final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService.getDataSet(
						"select convert(varchar(10), getDate(), 120) date",
						new AsyncCallback<DataSet>() {

							@Override
							public void onFailure(Throwable caught) {

							}

							@Override
							public void onSuccess(DataSet result) {

								String dateString = result.getValue(0, "date");
								Date date = DateUtil.castString2Date(dateString);
								Date passTime = DateUtil.castString2Date("2012-07-15");//试用日期请修改这里，然后编译
								if (passTime.before(date)) {
									MessageBox.alert("提示", "您的系统使用期限已过，请联系供应商开通，谢谢！", null);
									RootPanel.get("zgwtest").add(new Html("您的系统使用期限已过，请联系供应商开通，谢谢！"));
								} else {
									Login l = new Login();
						        	RootPanel.get("zgwtest").add(l.createForm());
								}
							}

						});
				     /*验证结束，请放开下面的代码，注解上面的代码====================
			         Login l = new Login();
			         RootPanel.get("zgwtest").add(l.createForm());*/
		         }
		      });
			
//			Login l = new Login();
//			return l.createForm();
		}
		else if(path.indexOf("Gwtbase.html")>0)
		{
			GWT.runAsync(new RunAsyncCallback(){
		         public void onFailure(Throwable err){
		        	 Window.alert("代码下载错误，错误可能源自网络链接已经断了。");
		         }
		 
		         public void onSuccess(){
		        	
		        	 RootPanel.get("zgwtest").add(new MainPage());
		         }
		      });
			
//			MainPage mpage = new MainPage();
//			return mpage;
		}
		
	}

}
